package com.hy.erp.inventory.service;

import java.util.List ;

import javax.annotation.Resource;

/*import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
*/
import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.DepotDao;
import com.hy.erp.inventory.dao.interfaces.ICargoSpaceDao;
import com.hy.erp.inventory.dao.interfaces.IUnitsDao;
import com.hy.erp.inventory.dao.interfaces.IDepotDao;
import com.hy.erp.inventory.pojo.Depot;
import com.hy.erp.inventory.pojo.interfaces.IUnits;
import com.hy.erp.inventory.pojo.interfaces.IDepot;
import com.hy.erp.inventory.service.interfaces.IDepotTypeService;
import com.hy.erp.inventory.service.interfaces.IDepotService;
import com.hy.erp.inventory.service.interfaces.IdepotDao;
/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-13；时间：上午09:18:05</li>
 * <li>类型名称：DepotService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
/*@ Name ( "depotService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless*/
public class DepotService extends AbstractBusinessService < DepotDao > implements IDepotService{

	
	private IdepotDao cargoSpaceDao=null;

	@Resource(name="cargoSpaceDao")
	public void setPositionTypeDao(ICargoSpaceDao cargoSpaceDao) {
		this.cargoSpaceDao = cargoSpaceDao;
	}
	@Override
	public boolean addDepot(Depot depot) {

		if (null == depot) {
			return true;
		}

		else {
			System.out
					.println("ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh");

	//		IDepotDao depotDao = (IDepotDao) this.getDao(IDepot.class);

			return depotDao.persist(depot);
		}

	}

	@Override
	public boolean modifyDepot(IDepot depot) {

		if ((null == depot) || (null == depot.getIdentifier())
				|| (depot.getIdentifier().trim().length() == 0)) {
			return true;
		} else {

			IDepotDao depotDao = (IDepotDao) this.getDao(IDepot.class);

			if (null == depot) {
				throw new ArchitectureFoundationException(
						"修改实体数据时发生错误，所需要修改的实体在数据库中并不存在");
			}

			return (depotDao.merge(depot) != null);
		}

	}

	@Override
	public Integer removeDepot(String[] depotIds) {

		if ((null == depotIds) || (depotIds.length == 0)) {
			return new Integer(0);
		} else {

			IDepotDao depotDao = (IDepotDao) this.getDao(IDepot.class);

			return depotDao.remove(depotIds);
		}

	}

	@Override
	public String[] addDepot(Object[] depot) {
		if (null == depot) {
			return null;
		}

		else {

			IDepotDao depotDao = (IDepotDao) this.getDao(IDepot.class);

			depot[] depots = new depot[depot.length];
			for (int i = 0; i < depot.length; i++) {
				depot depot2 = (depot) depot[i];
				depots[i] = depot2;
			}
			return depotDao.persist(depots);

		}

	}

	@Override
	public List<IDepot> getAllDepot() {
		IDepotDao depotDao = (IDepotDao) this.getDao(IDepot.class);

		return depotDao.find();
	}

	@Override
	public List<IDepot> getdepotByIds(String[] Ids) {
		if ((null == Ids) || (Ids.length == 0)) {
			return null;
		} else {
			IDepotDao depotDao = (IDepotDao) this.getDao(IDepot.class);

			return depotDao.findByIdentifier(Ids);

		}
	}

	@Override
	public IDepot getDepotById(String id) {

		if (null == id) {
			return null;
		} else {
			IDepotDao depotDao = (IDepotDao) this.getDao(IDepot.class);

			return depotDao.findByIdentifier(id);

		}

	}

	@Override
	public IDepot getDepotById(AbstractPersistentEntity baseModel) {

		if (null == baseModel) {
			return null;
		} else {
			String id = baseModel.get("identifier");

			IDepotDao depotDao = (IDepotDao) this.getDao(IDepot.class);

			return depotDao.findByIdentifier(id);

		}

	}

	@Override
	public String[] modifyDepot(Object[] depot) {

		if (null == depot) {
			return null;
		}

		else {

			IDepotDao depotDao = (IDepotDao) this.getDao(IDepot.class);

			depot[] depots = new depot[depot.length];
			for (int i = 0; i < depot.length; i++) {
				depot depot2 = (depot) depot[i];
				depots[i] = depot2;
			}
			return depotDao.merge(depots);

		}

	}

	@Override
	public boolean modifyDepot(Depot depot) {
		// TODO Auto-generated method stub
		return false;
	}

}
